<?php
require_once("conf/db_connection.php");
$source= $_POST['source'];
$booking_num= $_POST['booking_num'];
$qty= $_POST['qty'];
$size= $_POST['size'];
$ves_voy= $_POST['ves_voy'];
$ves_voy_etd= $_POST['ves_voy_etd'];
$pick_date= $_POST['pick_date'];
$pick_hour= $_POST['pick_hour'];
$pick_min= $_POST['pick_min'];
$shipper= $_POST['shipper'];
$shipper_code= $_POST['shipper_code'];
$commodity_class= $_POST['commodity_class'];
$pick_add= $_POST['pick_add'];
$con_per= $_POST['con_per'];
$con_num= $_POST['con_num'];
$instruction= $_POST['instruction'];
$type= $_POST['type'];

$query_insert = "INSERT INTO trip_detail (booking_source,booking_number,quantity,container_size,vessel_voyage,vessel_voyage_etd,positioning_date,positioning_time,customer,shipper_code,commodity_type,pick_address,contact_person,contact_number,instruction,type,created_by,is_interfaced) VALUES
('".$source."',
'".$booking_num."',
'".$qty."',
'".$size."',
'".$ves_voy."',
'".$ves_voy_etd."',
'".$pick_date."',
'".$pick_hour.":".$pick_min."',
'".$shipper."',
'".$shipper_code."',
'".$commodity_class."',
'".$pick_add."',
'".$con_per."',
'".$con_num."',
'".$instruction."',
'".$type."',
'".$_SESSION['username_nn']."',
'0')";
mysql_query($query_insert) or die("INSERT BOOKING ".mysql_error());

$query_last = "SELECT last_insert_id(id) as lid FROM trip_detail ORDER BY ID DESC LIMIT 0,1";
$result_last = mysql_query($query_last) or die($query_last);
$row_last = mysql_fetch_array($result_last);
$lid = $row_last['lid'];

$trip = $lid;

$gen_tas = "";
$conf_prefix = "TAS";
$conf_zero = 6;
$num_zero = $conf_zero - strlen($trip);

while($num_zero>0)
{
	$zero .= '0';
	$num_zero--;
}
$gen_tas = $conf_prefix.$zero.$trip;

$query_up = "UPDATE trip_detail SET tas_number='".$gen_tas."' WHERE id='".$lid."'";
mysql_query($query_up) or die("UPDATE TAS NUMBER ".mysql_error());

echo "1";
?>